import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _class2;

/**
 * AddSecGrpModal - 新建安全组弹窗

 */
import React from 'react';
import { Form, Input, Modal, Table, Button, notification, Row, Col } from 'antd';
import { Bind } from 'lodash-decorators';
import intl from 'utils/intl';
import { filterNullValueObject } from 'utils/utils';
import { SEARCH_FORM_ITEM_LAYOUT } from 'utils/constants';
/**
 * 使用 Form.Item 组件
 */

var FormItem = Form.Item;
var AddSecGrpModal = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec6 = Bind(), _dec7 = Bind(), _dec8 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(AddSecGrpModal, _React$Component);

  var _super = _createSuper(AddSecGrpModal);

  function AddSecGrpModal(props) {
    var _this;

    _classCallCheck(this, AddSecGrpModal);

    _this = _super.call(this, props);
    props.onRef(_assertThisInitialized(_this));
    _this.state = {
      addRows: []
    };
    return _this;
  }
  /**
   * 点击确定触发事件
   */


  _createClass(AddSecGrpModal, [{
    key: "okHandle",
    value: function okHandle() {
      var addData = this.props.addData;
      var addRows = this.state.addRows;

      if (addRows.length) {
        addData(addRows);
      } else {
        notification.warning({
          message: intl.get('cpaas.common.validation.atLeast').d('请至少选择一条数据')
        });
      }
    }
    /**
     * 点击取消触发事件
     */

  }, {
    key: "cancelHandle",
    value: function cancelHandle() {
      var onHideAddModal = this.props.onHideAddModal;

      if (onHideAddModal) {
        onHideAddModal(false);
      }
    }
    /**
     *分页change事件
     */

  }, {
    key: "handleTableChange",
    value: function handleTableChange() {
      var pagination = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var _this$props = this.props,
          fetchModalData = _this$props.fetchModalData,
          form = _this$props.form;
      var filterValues = filterNullValueObject(form.getFieldsValue());

      if (fetchModalData) {
        fetchModalData(_objectSpread({
          page: pagination
        }, filterValues));
      }
    }
    /**
     * 表格勾选
     * @param {null} _ 占位
     * @param {object} selectedRow 选中行
     */

  }, {
    key: "onSelectChange",
    value: function onSelectChange(_, selectedRow) {
      this.setState({
        addRows: selectedRow
      });
    }
    /**
     * 表单重置
     */

  }, {
    key: "handleFormReset",
    value: function handleFormReset() {
      var form = this.props.form;
      form.resetFields();
    }
    /**
     * 查询方法
     */

  }, {
    key: "queryValue",
    value: function queryValue() {
      var _this$props2 = this.props,
          form = _this$props2.form,
          fetchModalData = _this$props2.fetchModalData;

      if (fetchModalData) {
        var filterValues = filterNullValueObject(form.getFieldsValue());
        fetchModalData(filterValues || {});
      }

      this.setState({
        addRows: []
      });
    }
  }, {
    key: "renderForm",
    value: function renderForm() {
      var _this$props3 = this.props,
          queryCode = _this$props3.queryCode,
          queryName = _this$props3.queryName,
          queryCodeDesc = _this$props3.queryCodeDesc,
          queryNameDesc = _this$props3.queryNameDesc;
      var getFieldDecorator = this.props.form.getFieldDecorator;
      return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Row, {
        type: "flex",
        gutter: 24,
        align: "bottom"
      }, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: queryNameDesc
      }), getFieldDecorator("".concat(queryName))( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({}, SEARCH_FORM_ITEM_LAYOUT, {
        label: queryCodeDesc
      }), getFieldDecorator("".concat(queryCode))( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, null, /*#__PURE__*/React.createElement(Button, {
        style: {
          marginRight: 8
        },
        onClick: this.handleFormReset
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.queryValue
      }, intl.get('cpaas.common.button.search').d('查询'))))));
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props4 = this.props,
          title = _this$props4.title,
          modalVisible = _this$props4.modalVisible,
          loading = _this$props4.loading,
          confirmLoading = _this$props4.confirmLoading,
          rowKey = _this$props4.rowKey,
          _this$props4$columns = _this$props4.columns,
          columns = _this$props4$columns === void 0 ? [] : _this$props4$columns,
          _this$props4$dataSour = _this$props4.dataSource,
          dataSource = _this$props4$dataSour === void 0 ? [] : _this$props4$dataSour,
          _this$props4$paginati = _this$props4.pagination,
          pagination = _this$props4$paginati === void 0 ? {} : _this$props4$paginati,
          _this$props4$isQuery = _this$props4.isQuery,
          isQuery = _this$props4$isQuery === void 0 ? true : _this$props4$isQuery;
      var addRows = this.state.addRows;
      var rowSelection = {
        onChange: this.onSelectChange,
        selectedRowKeys: addRows.map(function (n) {
          return n[rowKey];
        })
      };
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        confirmLoading: confirmLoading,
        title: title,
        visible: modalVisible,
        onOk: this.okHandle,
        width: 800,
        onCancel: this.cancelHandle
      }, isQuery && /*#__PURE__*/React.createElement("div", {
        className: "table-list-search"
      }, this.renderForm()), /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        rowKey: rowKey,
        columns: columns,
        loading: loading,
        dataSource: dataSource,
        rowSelection: rowSelection,
        pagination: pagination,
        onChange: this.handleTableChange
      }));
    }
  }]);

  return AddSecGrpModal;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "okHandle", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "okHandle"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "cancelHandle", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "cancelHandle"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleTableChange", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleTableChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "onSelectChange", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "onSelectChange"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFormReset", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFormReset"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "queryValue", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "queryValue"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "renderForm", [_dec8], Object.getOwnPropertyDescriptor(_class2.prototype, "renderForm"), _class2.prototype)), _class2)) || _class);
export { AddSecGrpModal as default };